from django.db import models


# Create your models here.
class Book(models.Model):
    name = models.CharField(max_length=32, null=False, unique=True, verbose_name='书名')
    price = models.DecimalField(max_digits=38, decimal_places=1, default=0, verbose_name='价格')
    register_date = models.DateField(auto_now_add=True, verbose_name='出版日期')
    desc = models.TextField(default='这是一本好书')
    image = models.TextField(default='https://pic.netbian.com/uploads/allimg/231215/115840-1702612720bb34.jpg')
    url = models.TextField(default='')
    word_count = models.CharField(max_length=32, default='0')
    # 一对多
    publish = models.ForeignKey(to='publish.Publish', on_delete=models.CASCADE, verbose_name='出版社')
    # 多对多
    author = models.ManyToManyField(to='author.Author', verbose_name='作者')

    def __str__(self):
        return f"{self.name} 书籍对象"

    class Meta():
        db_table = "book"
        verbose_name_plural = "图书表"
